#include "CTranslateResultItemWidget.h"
#include "ui_CTranslateResultItemWidget.h"

#include <QApplication>
#include <QClipboard>

CTranslateResultItemWidget::CTranslateResultItemWidget(QWidget* parent)
    : QWidget(parent),
      ui(new Ui::CTranslateResultItemWidget)
{
    ui->setupUi(this);
}

CTranslateResultItemWidget::~CTranslateResultItemWidget()
{
    delete ui;
}

void CTranslateResultItemWidget::RefreshWidget()
{
    ui->plainTextEdit->clear();
    ui->btnCopy->setText("复制");
}

void CTranslateResultItemWidget::leaveEvent(QEvent* event)
{
    // ui->btnCopy->setText("复制");
}

void CTranslateResultItemWidget::AppendText(const QString& text)
{
    ui->plainTextEdit->insertPlainText(text);
}

void CTranslateResultItemWidget::on_btnCopy_clicked()
{
    // 获取系统剪贴板对象
    QClipboard* clipboard = QApplication::clipboard();

    // 将文本设置到剪贴板
    clipboard->setText(ui->plainTextEdit->toPlainText());

    ui->btnCopy->setText("复制成功！");
}
